//
//  UIButton+Extension.swift
//  WeiBo
//
//  Created by 张德华 on 7/23/16.
//  Copyright © 2016 ZhangDeHua. All rights reserved.
//

import UIKit

extension UIButton {
    
    
    
    ///  创建Button
    ///
    ///  - parameter title:           title
    ///  - parameter titleColor:      titleColor 默认橘黄色
    ///  - parameter titleTextFont:   titleTextFont 默认14
    ///  - parameter imageName:       imageName 前景图片 默认nil
    ///  - parameter backgroundImage: backgroundImage 背景图片 默认nil
    ///
    ///  - returns: UIButton
    convenience init(wq_title title: String,
                              titleColor: UIColor = UIColor.orangeColor(),
                              titleTextFont: CGFloat = 14,
                              imageName: String? = nil,
                              backgroundImage: String? = nil) {
        
        self.init()
        
        self.setTitle(title, forState: UIControlState.Normal)
        self.setTitleColor(titleColor, forState: UIControlState.Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(titleTextFont)
//        
//        self.setBackgroundImage(UIImage(named:backgroundImage!), forState: UIControlState.Normal)
        
        if let image = imageName {
            self.setImage(UIImage(named: image), forState: UIControlState.Normal)
            self.setImage(UIImage(named: image + "_highlight"), forState: UIControlState.Highlighted)
        }
        
        if let backImage = backgroundImage {
            self.setBackgroundImage(UIImage.init(named: backImage), forState: UIControlState.Normal)
            self.setBackgroundImage(UIImage.init(named: backImage + "_highlight"), forState: UIControlState.Highlighted)
        }
        
        sizeToFit()

    }
    
    
}


